package com.ui.basic.ibatis.dao;

import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;

@Repository("commonDAO")
public class CommonDAOImpl implements CommonDAO {
	private static final transient org.apache.commons.logging.Log LOGGER = org.apache.commons.logging.LogFactory.getLog(CommonDAOImpl.class);

	@Autowired private SqlMapClient sqlMapClient;

	public CommonDAOImpl() {
		super();
	}

	@Autowired
	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}

	public Date getServerDate() throws SQLException {
		LOGGER.debug("CommonDAOImpl.getServerDate");
		Date result;
		result = (Date) sqlMapClient.queryForObject("Common.getServerDate", "");
		return result;
	}

	@SuppressWarnings("unchecked")
	public String getSystemMaster(String systemKey) throws SQLException {
		LOGGER.debug(">>>>>>>>CommonDAOImpl.getSystemMaster");
		Map map = new HashMap();
		map.put("SYSTEM_KEY", systemKey);

		String result;

		result = (String) sqlMapClient.queryForObject(
				"Common.selectSystemMaster", map);

		return result;
	}

	@SuppressWarnings("unchecked")
	public String convertMD5(String password) throws SQLException {
		LOGGER.debug(">>>>>>>>CommonDaoImpl.convertMD5");
		Map map = new HashMap();
		map.put("PASSWORD", password);
		String result;
		result = (String) sqlMapClient.queryForObject("Common.convertMD5", map);
		sqlMapClient.flushDataCache();
		return result;
	}
}